//
//  RWToolBar.m
//  04-ipadQQ
//
//  Created by 紫荆秋雪 on 16/4/7.
//  Copyright © 2016年 紫荆秋雪. All rights reserved.
//

#import "RWToolBar.h"

@implementation RWToolBar

- (instancetype)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    if (self) {
        
        //1、创建内容
        [self setupToolBarSubBtn:@"tabbar_photo"];
        [self setupToolBarSubBtn:@"tabbar_mood"];
        [self setupToolBarSubBtn:@"tabbar_blog"];
        
    }
    return self;
}

#pragma mark -创建子控件的私有方法
- (void)setupToolBarSubBtn:(NSString *)imageName
{

    UIButton *btn = [[UIButton alloc] init];
    
    //2、设置图片
    [btn setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    
    //3、按钮被选中
//    [btn setImage:[UIImage
    
    [btn setBackgroundImage:[UIImage imageNamed:@"tabbar_separate_selected_bg"] forState:UIControlStateHighlighted];
    
    //添加到父控件
    [self addSubview:btn];

}

#pragma mark -子控件布局
- (void)layoutSubviews{

    [super layoutSubviews];
    //子控件个数
    NSInteger num = self.subviews.count;
    //判断屏幕
    if (Lanscape) {//横屏

        for (NSInteger i = 0; i<num; i++) {
            
            UIButton *btn = self.subviews[i];
            btn.width = self.width * 1.0 / num;
            btn.height = self.height;
            btn.x = i * btn.width;
            btn.y = 0;
        }
        
    }else {
    
        for (NSInteger i = 0; i<num; i++) {
            
            UIButton *btn = self.subviews[i];
            btn.width = self.width;
            btn.height = btn.width;
            btn.x = 0;
            btn.y = i * btn.height;
        }
    }
    
}

@end
